fix(lsp): allow plugins to override document and root uri handling#1999
Conversation
Greptile SummaryThis PR allows LSP plugin authors to override both document URI and root URI resolution by adding a new Key changes:
The Confidence Score: 5/5Safe to merge — core logic is well-structured, all findings are P2 style/consistency suggestions, and no regressions are introduced. All three comments are P2: one notes a pre-existing inconsistency in formatDocument (not a regression), one suggests exporting MaybePromise, and one flags the intentional #resolveRootUri priority change as worth documenting. None represent a current defect on the primary attach/detach path exercised by getExtensionsForFile. src/cm/lsp/clientManager.ts — the formatDocument attach-without-aliases gap and the #resolveRootUri reorder are both in this file. Important Files Changed
Sequence DiagramsequenceDiagram
participant EM as editorManager
participant CM as LspClientManager
participant RDU as resolveDocumentUri
participant RRU as resolveRootUri
participant CS as ClientState
EM->>CM: getExtensionsForFile(metadata)
loop for each matching server
CM->>RDU: resolveDocumentUri(server, context)
RDU->>RDU: normalizeDocumentUri(originalUri)
alt normalizedUri is null
RDU->>RDU: buildFileUri(file.cacheFile)
end
alt server.documentUri is function
RDU->>RDU: await server.documentUri(originalUri, ctx+normalizedUri)
end
RDU-->>CM: normalizedUri (or null, skip server)
CM->>RRU: resolveRootUri(server, context)
Note over RRU: Priority: server.rootUri fn, context.rootUri, options.resolveRoot
RRU-->>CM: rootUri
CM->>CS: attach(normalizedUri, view, aliases=[originalUri])
Note over CS: uriAliases: originalUri to normalizedUri
end
EM->>CM: detach(originalUri, view)
CM->>CS: detach(originalUri, view)
Note over CS: actualUri = uriAliases.get(originalUri) = normalizedUri
CS->>CS: fileRefs.delete(normalizedUri)
CS->>CS: cleanup uriAliases entries pointing to normalizedUri
CS->>CS: workspace.closeFile(normalizedUri)
|
Fixes: #1996